<template>
	<view>
		<canvas canvas-id="myCanvas" :style="'width:'+windowWidth+'px;height:'+windowHeight+'px'" />
	</view>
</template>

<script>
	import myCloud from '@/common/util/cloud.js';
	import myConst from '@/common/util/const.js';
	import {
		base64ToPath
	} from '@/common/util/util.js';
	export default {
		data() {
			return {
				windowWidth: 500,
				windowHeight: 800,
				qrCodeBbase64: '',
			
			}
		},
		onLoad(options) {
			const {
				windowWidth,
				windowHeight
			} = uni.getSystemInfoSync();
			this.windowWidth = windowWidth;
			this.windowHeight = windowHeight;
			// myCloud.callFunction('s_get_qrcode', {}, (data, e) => {

			// 	const arrayBuffer = new Uint8Array(data.buffer.data)
			// 	const base64 = uni.arrayBufferToBase64(arrayBuffer)
			// 	this.qrCodeBbase64 = base64;

			// }, false)
		},
		onShow() {
			
			
		},
		onReady() {
			var that = this;

			const ctx = uni.createCanvasContext('myCanvas', that)
			ctx.save()
			ctx.rect(0, 100, that.windowWidth, that.windowHeight - 200)
			ctx.setFillStyle('#f0f0f0')
			ctx.fill()

			// uni.getImageInfo({
			//            src: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1590833431377&di=0df1a2c01b226b6c433889d1102de670&imgtype=0&src=http%3A%2F%2Fa2.att.hudong.com%2F36%2F48%2F19300001357258133412489354717.jpg",
			//            success: function (image) {
			//                console.log(image.width);
			//                console.log(image.path);
			// 			ctx.drawImage(image.path, 50, 0, 200, 300)
			// 			ctx.draw()
			// 			this.preview()
			//            }
			//        });
			// var img = 'data:image/png;base64,' + that.qrCodeBbase64;
			// base64ToPath(img).then(path => {
			// 	console.log(123)
			// 	console.log(path)
			// 	ctx.drawImage(path, 10, 150, 200, 300)
			// 	ctx.draw()
			// 	this.preview()
			// })
			//商品图片




			//商品名称
			// ctx.setFontSize(20)
			// ctx.fillText(that.productName, 20, 350)

			// //商品价格
			// ctx.setFontSize(20)
			// ctx.fillText(that.skuRetailPrice, 20, 380)

			// //用户信息
			// ctx.setFontSize(20)
			// ctx.fillText("推荐好物", 20, 310)

			//二维码
	ctx.drawImage('./../../static/avatar.png', 50, 0, 200, 300)
						ctx.draw()
						// this.preview()
setTimeout(()=>{
			 
			  that.preview();
			  
			},100);
		},
		methods: {
			preview() {

				var that = this
	
				uni.canvasToTempFilePath({
					canvasId: 'myCanvas',
					success: function(res) {
						// 在H5平台下，tempFilePath 为 base64
						console.log(12312)
						console.log(res.tempFilePath)
						uni.previewImage({
							urls: [res.tempFilePath],
							longPressActions: {
								itemList: ['发送给朋友', '保存图片', '收藏'],
								success: function(data) {
									console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
								},
								fail: function(err) {
									console.log(err.errMsg);
								}
							}
						});
					},
					fail: function(res) {
						console.log("bbbbb")
						console.log(res)
					}
				}, this)
			}
		}
	}
</script>

<style>
</style>